// nic.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int cardif_dump(FILE *fp)
{
	pcap_if_t *alldevs;
	pcap_if_t *d;
	int i=0;
	char errbuf[PCAP_ERRBUF_SIZE];
	
	/* Retrieve the device list */
	if(pcap_findalldevs(&alldevs, errbuf) == -1)
	{
		fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
		exit(1);
	}
	
	/* Print the list */
	for(d=alldevs; d; d=d->next)
	{
		fprintf(fp, "%d.%s.", ++i, d->name);
		if (d->description)
			fprintf(fp, " (%s)\n", d->description);
		else
			fprintf(fp, " (No description available)\n");
	}
	
	if(i==0)
	{
		printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
		return -1;
	}
	
	pcap_freealldevs(alldevs);
	return 0;
}

int main(int argc, char* argv[])
{
	FILE *fp;
	if( (fp=fopen("nic.txt","w"))==NULL ) {
		printf("error\n\r");
		return -1;
   	}
	cardif_dump(fp);
	fclose(fp);
	printf("OK!");
	return 0;
}

